package org.spiderflow.common.utils;

import org.springframework.util.ResourceUtils;

import java.io.File;

/**
 * @Author: tjs
 * @Date: 2019/5/19 22:43
 * @Desc:
 */
public class CommonUtils {

    //如果上传目录为/static/images/upload/,则可以如下获取


    public static String getUrl(String fileName) throws Exception{
        File path=new File(ResourceUtils.getURL("classpath:").getPath());
        System.out.println("path1>>>>>>>"+path);
        if(!path.exists()){
            path=new File("");
        }
        File upload=new File(path.getAbsolutePath(),"static/images/");
        if(!upload.exists()){
            upload.mkdirs();
            System.out.println("path2>>>>>>>"+upload.getAbsolutePath());
            //在开发测试模式时，得到地址为：{项目跟目录}/target/static/images/upload/
            //在打成jar正式发布时，得到的地址为:{发布jar包目录}/static/images/upload/
        }
        System.out.println("path3>>>>>>>"+path.getAbsolutePath() +"/" +fileName);
        return path.getAbsolutePath() + "/" + fileName;
    }

    public static String getFileName(int fileType,String fileName){
        return fileType+"_" +UUIDGenerator.getUUID() +"_" + fileName;
    }

    public static String getUrl(String modleName,String fileName){
        return System.getProperty("user.dir") + "/"+modleName+ "/" + UUIDGenerator.getUUID() +"_" +fileName;
    }
}
